<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use DB;
use App\Models\Pictuer;
class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth')->except('index');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        return view('welcome');
    }

    public function sqldump(Request $request)
    {
        $users = DB::connection('sqlback')->table('tx_tagpiclist')->paginate(200);
        if(count($users) < 1) return 'm,eiyoule';
        foreach($users as $user) {
            if ($pictuer = Pictuer::find($user->pid)) {
                $pictuer->tags()->attach($user->tagid);
            }
        }

        $page = $request->page ?: 1;
        $page++;
        $url = route('sqldump', ['page' => $page]);
        return '
        <script>window.location.href = "' . $url . '"</script>
        ';
    }
}
